package com.ytzl.itrip.search.controller;

import com.alibaba.fastjson.JSONObject;
import com.ytzl.itrip.beans.model.vo.*;
import com.ytzl.itrip.biz.service.ItripHotelService;
import com.ytzl.itrip.search.service.SearchHotelService;
import com.ytzl.itrip.utils.common.Dto;
import com.ytzl.itrip.utils.common.DtoUtil;
import com.ytzl.itrip.utils.common.EmptyUtils;
import com.ytzl.itrip.utils.common.Page;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by asus on 2018/7/18.
 */
@Controller
@RequestMapping("/api/hotellist")
public class itripSearchController {

    @Resource
    private SearchHotelService searchHotelService;

    @RequestMapping(value = "/searchItripHotelPage",method = RequestMethod.POST)
    @ResponseBody
    public Dto searchItirpHotelPage(@RequestBody SearchHotelVo searchHotelVo){
        if (EmptyUtils.isNotEmpty(searchHotelVo.getDestination())){
            try {
                Page<Hotel> page = searchHotelService.searchHotelListByHotCity(searchHotelVo);
                return DtoUtil.returnDataSuccess(page);
            } catch (Exception e) {
                e.printStackTrace();
                return DtoUtil.returnFail("系统异常，获取失败","20001");
            }
        }else {
            return DtoUtil.returnFail("目的地不能为空","20002");
        }
    }


    @RequestMapping(value = "/searchItripHotelListByHotCity",method = RequestMethod.POST)
    @ResponseBody
    public Dto searchItripHotelListByHotCity(@RequestBody SearchHotCityVo searchHotCityVo){
        if (searchHotCityVo.getCityId()==null){
            return DtoUtil.returnFail("城市id不能为空","20004");
        }else {
            try {
                List<Hotel> hotels = searchHotelService.searchHoteByHotCity(searchHotCityVo);
                return DtoUtil.returnSuccess("获取热门城市酒店",hotels);
            } catch (Exception e) {
                e.printStackTrace();
                return DtoUtil.returnFail("系统异常，获取失败","20003");
            }
        }
    }
}
